package com.learning.walter.pattern.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class LolProxy implements InvocationHandler {

	private LolPlayer player;

	public Object getInstance(LolPlayer player) {
		this.player = player;
		Class<? extends LolPlayer> targetClass = player.getClass();
		return Proxy.newProxyInstance(targetClass.getClassLoader(), targetClass.getInterfaces(), this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

		System.out.println("我是代练,帮你上分!");
		method.invoke(player, args);

		return null;
	}

}
